<%@ page import="databeans.*"%>
<%@ page import="java.util.*" %>
<%@ page import="model.*" %>


<div id="box">
   	<h3>Transaction History</h3>
   	<jsp:include page="../common/messages.jsp"/>
   	<%
   	/*
   		ArrayList<String> transDates_execute = (ArrayList<String>)request.getAttribute("transDates_execute");
	  	ArrayList<String> transDates_submit = (ArrayList<String>)request.getAttribute("transDates_submit");
	  	ArrayList<String> transTypes = (ArrayList<String>)request.getAttribute("transTypes");
		ArrayList<String> fundNames = (ArrayList<String>)request.getAttribute("fundNames");
		ArrayList<Double> numOfShares = (ArrayList<Double>)request.getAttribute("numOfShares");
		ArrayList<Double> sharePrices = (ArrayList<Double>)request.getAttribute("sharePrices");
		ArrayList<Double> amounts = (ArrayList<Double>)request.getAttribute("amounts");
		ArrayList<String> statuses = (ArrayList<String>)request.getAttribute("statuses");
		*/
		Transaction[] transactions = (Transaction[])request.getAttribute("transactions");
		
		FundHistoryDAO fundHistoryDAO =  null;
	  	//if (transactions.length<=0){
  		if (transactions==null){

	  %>
	  <p class="pad-left-20">You have no transactions so far. </p>
		 <% 
		 }else{
		 %>
     	<div class="trans-history">
    		<table id="trans-history">
    			<thead>
					<tr>
						<th>ID</th>
						<th>Execute Date</th>
						<th>Submit Date</th>
					    <th>Transaction Type</th>
					    <th>Fund Name</th>
					    <th>Shares</th>
					    <th>Share Price</th>
					    <th>$ Amount</th>
					    <th>Status</th>
					</tr>
				</thead>
				<tbody>
				<% 
					for(int i=0; i<transactions.length; i++) {
						
				%>
					<tr>
						<td><%=transactions[i].getTransactionID() %></td>
						<td><%if(transactions[i].getExecuteDate()!=null) out.println(transactions[i].getExecuteDate()); else out.println("Pending"); %></td>
						<td><%=transactions[i].getSubmissionDate() %></td>
						<td><%=transactions[i].getTransactionType() %></td>
						<td><% //transactions[i].getFundName() %></td>
						<td><%if(transactions[i].getExecuteDate()==null){
								out.println("NA");
			  				}else{
			  					out.println(transactions[i].getShares());
			  				}	
	  					%></td>
						<td><% if(transactions[i].getExecuteDate()==null) 
							out.println("NA");
				  				else {
				  					 FundHistory fundHistory = fundHistoryDAO.lookup(transactions[i].getFundID(), transactions[i].getExecuteDate());
				  				     if(fundHistory==null)
				  				    	out.println("No Fund History founded.");
				  				     else
				  				    	 fundHistory.getPrice();
				  				}
	  					%></td>
	  					<td><%=transactions[i].getAmount() %></td>
						<td><%if (transactions[i].getExecuteDate()==null) {%> 
								<span class="pending pad-left-20">Pending</span>
							<%} else {%>
								<span class="tick pad-left-20">Approved</span>
								<%}
						%></td>
					</tr>
				<% } %>
				</tbody>
			</table>
   		</div>
   	<%} %>
</div>
<%/*

else {
								FundHistory fn =(FundHistory)request.getAttribute("fundHistory");
							%>
								<tr>
    							  <td><%= fn.getPriceDate() %></td>
    							  <td><%="$" + fn.getPrice() %></td>
  							  </tr>		
							<%
								}
*/
 %>